Write-Host "Starting offline build..." -ForegroundColor Green

# Set multiple environment variables to disable electron download
$env:ELECTRON_SKIP_BINARY_DOWNLOAD = "1"
$env:ELECTRON_CACHE = "./electron-cache"
$env:ELECTRON_BUILDER_CACHE = "./electron-builder-cache"
$env:ELECTRON_MIRROR = "https://npm.taobao.org/mirrors/electron/"
$env:ELECTRON_CUSTOM_DIR = "28.3.3"

# Ensure using local electron
$env:ELECTRON_PATH = "./node_modules/electron/dist/electron.exe"

# Additional electron-builder specific variables
$env:ELECTRON_BUILDER_CACHE = "./electron-builder-cache"
$env:ELECTRON_DOWNLOAD_MIRROR = "https://npm.taobao.org/mirrors/electron/"

# Disable winCodeSign download
$env:WIN_CODESIGN_SKIP_DOWNLOAD = "1"

# Disable nsis-resources download
$env:NSIS_RESOURCES_SKIP_DOWNLOAD = "1"

# Set nsis-resources cache path
$env:NSIS_RESOURCES_CACHE = "./cache/nsis-resources"
$env:ELECTRON_BUILDER_CACHE = "./cache"

Write-Host "Environment variables set:" -ForegroundColor Yellow
Write-Host "ELECTRON_SKIP_BINARY_DOWNLOAD=1" -ForegroundColor Cyan
Write-Host "ELECTRON_CACHE=./electron-cache" -ForegroundColor Cyan
Write-Host "ELECTRON_PATH=./node_modules/electron/dist/electron.exe" -ForegroundColor Cyan
Write-Host "ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/" -ForegroundColor Cyan
Write-Host "WIN_CODESIGN_SKIP_DOWNLOAD=1" -ForegroundColor Cyan
Write-Host "NSIS_RESOURCES_SKIP_DOWNLOAD=1" -ForegroundColor Cyan
Write-Host "NSIS_RESOURCES_CACHE=./cache/nsis-resources" -ForegroundColor Cyan
Write-Host "ELECTRON_BUILDER_CACHE=./cache" -ForegroundColor Cyan

Write-Host "Starting build..." -ForegroundColor Green
npx electron-builder --win

Write-Host "Build completed!" -ForegroundColor Green
Read-Host "Press any key to continue..." 